#coding:utf-8
import datetime
import pandas as pd
from pandas import DataFrame
import pymysql
import re
import json
from collections import defaultdict




def error(func):
    def wrapper(*args,**kargs):
        try:
            a = func(*args,**kargs)
            return a
        except Exception as e:
            DataFrame([[func.__name__,e,datetime.datetime.now()]]).to_csv('FuncWrong.csv',mode = 'a',index = None,header=None)
            return ''
    return wrapper
class ConFunc():
    def __init__(self,config):
        self.config = config

    def aoligeiganle(self,amount):
        if '整' in amount and amount[0] != '整':
            amount = amount.split('整')[0]
        chinese_num = {'零': 0, '壹': 1, '贰': 2, '叁': 3, '肆': 4, '伍': 5, '陆': 6, '柒': 7, '捌': 8, '玖': 9, '拾': 10}
        chinese_amount = {'分': 0.01, '角': 0.1, '元': 1, '拾': 10, '佰': 100, '百': 100, '仟': 1000, '圆': 1}
        amount_float = 0
        if amount[:2] == "万元":
            amount = amount[2:]
        elif amount[:1] == "元":
            amount = amount[1:]
        if '亿' in amount:
            yi = re.match(r'(.+)亿.*', amount).group(1)
            amount_yi = 0
            for i in chinese_amount:
                if i in yi:
                    amount_yi += chinese_num[yi[yi.index(i) - 1]] * chinese_amount[i]
            if yi[-1] in chinese_num.keys():
                amount_yi += chinese_num[yi[-1]]
            amount_float += amount_yi * 100000000
            amount = re.sub(r'.+亿', '', amount, count=1)

        if '万' in amount and amount[0] != '万':
            wan = re.match(r'(.+)万.*', amount).group(1)
            amount_wan = 0
            if wan == '拾':
                amount_wan = 10
            elif wan == '佰':
                amount_wan = 100
            else:
                for i in chinese_amount:
                    if i in wan:

                        amount_wan += chinese_num[wan[wan.index(i) - 1]] * chinese_amount[i]

            if wan[-1] in chinese_num.keys() and wan[-1] not in ['拾','佰']:
                amount_wan += chinese_num[wan[-1]]

            amount_float += amount_wan * 10000
            amount = re.sub(r'.+万', '', amount, count=1)

        amount_yuan = 0
        for i in chinese_amount:
            if i in amount:
                if amount[amount.index(i) - 1] in chinese_num.keys():
                    amount_yuan += chinese_num[amount[amount.index(i) - 1]] * chinese_amount[i]
        amount_float += amount_yuan
        return amount_float

    def is_number(self,value):
        obj = re.search(r"[^0-9\.]", value, re.M | re.I | re.S)
        if obj or (value == ""):
            return False
        else:
            return True

    def get_money(self,value):

        value = re.split('\.\.',value)[0]
        if value == '':
            return value
        if value[-1] == '.':
            value = value[:-1]
        value = re.sub("\s|:|◄", "", value, flags=re.S | re.I)
        ls = [['百', '佰'],
              ['玫', '玖'],
              ['项', '貳']
              ]
        for i in ls:
            value = value.replace(i[0], i[1])
        if re.search('(\d+万?)[元圆]整', value):
            value = re.search('(\d+万?)[元圆]整', value).group(1)
            if '万' in value:
                value = value[:-1]
            else:
                value = round(float(value) / 10000, 6)
            return value

        if re.search('^\d+\.?\d{0,}万元?$', value):
            value = value.split('万')[0]
            return value

        if re.search('^\d+佰万元?$', value):
            value = value.split('佰万')[0]
            return value + '00'
        obj = re.search("[零壹贰貳叁肆伍陆柒捌玖拾佰仟萬亿圆元万整]{3,}", value, re.I | re.S)
        if obj:
            china_char = obj.group()
            value = str(self.aoligeiganle(china_char))

        move_char = re.sub("[（万元）中标,总金额◄:]", "", value, flags=re.S | re.I)
        if re.search('\d\.\d\.\d',move_char):
            return '0'
        obj = re.search('(\d+)\.(\d+).(\d+)',move_char)
        if obj:
            move_char = obj.group(1)+'.'+obj.group(2)
        if move_char != "":
            if self.is_number(move_char):
                if value != "":
                    if "万" in value:
                        value = move_char
                    else:
                       value = round(float(move_char) / 10000, 6)

        else:
            value = "0"
        return value

    def rubbish_word(self,word):
        tag_ls = self.config['tag_ls']
        word = word.replace(':', '：')
        word = word.replace('(', '（')
        word = word.replace(')', '）')
        if len(word) > 30:
            return word
        ls = [
            '中标单位联系(人|方式)',
            '报价得分',
            '未提交最终报价',
            '其他报价',
            '标段（?包?）?编号',
            '中标(供应商|人)(统一社会信用)?代码',
            '价格分',
            '金额说明',
            '^单价',
            '文件递交顺序',
            '(参加|有效)投标企业',
            '中标候选人排序及相关内容',
            '惩罚',
            '收费标准：',
            '识别码'
        ]
        for i in ls:
            bb = '中标单位及地址|([院站处队局所部社厂场室行校]|中心|公司|联合体)|委员会'
            if re.search(i, word) != None and re.search(bb, word) == None:
                if word in tag_ls:
                    word = 'rubbish_word_tag'
                else:
                    word = 'rubbish_word_ntag'
        return word

    def replace_word(self,word):
        if word == '':
            return word
        word = word.replace(':', '：')
        if word[-1] == '：':
            word = word.replace('：', '')
        word = word.replace('(', '（')
        word = word.replace(')', '）')
        word = word.replace('?', '？')
        word = re.sub('[￥。]', '', word)
        if word == '':
            word = '/'
        if len(word) > 30:
            return word
        for i in self.config['table_clear_word']:
            word = re.sub(i[0],i[1],word)

        for i in self.config['table_replace_word']:
            if i == '中标公司_':
                aa = self.config['table_replace_word'][i][0]
                bb = self.config['table_replace_word'][i][1]
                b = re.search(aa, word)
                if b != None and (re.search(bb, word) == None or word[-1] == '：'):
                    so = b.group(1)
                    so_dict = {'1': '一', '2': '二', '3': '三', '4': '四', '5': '五'}
                    if so[1] in so_dict.keys():
                        so = '第' + so_dict[so[1]]
                    word = '中标公司' + '_' + so
                    break

            if re.search(self.config['table_replace_word'][i][0], word) and re.search(self.config['table_replace_word'][i][1], word) == None:
                if i[:4] == '中标金额':
                    if '（' in word and (re.search('[万%]', word) != None):
                        temp = word[word.index('（'):]
                    else:
                        temp = ''
                    if i == '中标金额_especial':
                        word = i + temp
                        break
                    else:
                        if re.search('[上下]浮|率', word) and temp == '':
                            word = '中标金额（%）'
                        else:
                            word = '中标金额' + temp
                        break
                if re.search('^(预算金额|投资额|代理服务收费标准及金额|最高限价)',i):
                    if '（' in word and (re.search('[万%]', word) != None):
                        temp = word[word.index('（'):]
                    else:
                        temp = ''
                    if re.search('[上下]浮|率', word) and temp == '':
                        word = i + '（%）'
                    else:
                        word = i + temp
                    break
                if i == '标段' and len(word) > 10:
                    continue
                word = i
                break
        return word

    def clear_solo(self,html,dispose_solo_text_dict,id = ''):
        if id == '':
            return html
        else:
            re_ls_solo = dispose_solo_text_dict
            id = int(id)
            if int(id) in re_ls_solo:
                re_ls = re_ls_solo[id]
                for i in re_ls:
                    try:
                        html = re.sub(i[0], i[1], html,re.I|re.M|re.S)
                    except:
                        print('re1 wrong.............')
                        continue

        return html

class Conf():
    def __init__(self,**kargs):
        self.config = {}
        self.conn = kargs['conn']
        self.cursor = kargs['cursor']
    def tag(self):
        tag_ls = []
        self.conn.ping(reconnect=True)
        self.cursor.execute(
            'select distinct key_name from dispose.analyze_key_tag_copy1 union select name_change from dispose.analyze_key_tag_copy1')
        data = self.cursor.fetchall()
        for i in data:
            tag_ls.append(i['key_name'])
        self.config['tag_ls'] = tag_ls

    def public_word(self):
        sql = 'select * from analyze_dispose where tag = 2'
        self.cursor.execute(sql)
        data = self.cursor.fetchall()
        self.config['res_ls'] = []
        for i in data:
            if i['UseKey'] != 'res_ls':
                self.config[i['UseKey']] = [i['NeedMatch'], i['NoMatch']]
            else:
                self.config['res_ls'].append([i['NeedMatch'], i['NoMatch']])


    def table_clear_word(self):
        sql = 'select * from analyze_dispose where tag = 0'
        self.cursor.execute(sql)
        data = self.cursor.fetchall()
        replace_word_ls = []
        for i in data:
            replace_word_ls.append([i['NeedMatch'],i['UseKey']])
        self.config['table_clear_word'] = replace_word_ls

    def table_replace_word(self):
        sql = 'select * from analyze_dispose where tag = 1'
        self.cursor.execute(sql)
        data = self.cursor.fetchall()
        replace_word_dict = {}
        for i in data:
            replace_word_dict[i['UseKey']] = [i['NeedMatch'],i['NoMatch']]
        self.config['table_replace_word'] = replace_word_dict

    def text_replace_word(self,company_chose):
        sql = 'select * from analyze_dispose where tag = 3'
        self.cursor.execute(sql)
        data = self.cursor.fetchall()
        replace_word_ls = []
        for i in data:
            replace_word_ls.append([i['NeedMatch'],i['UseKey']])

        replace_word_ls.append(["确定([^,;\.。]{5,30})" + company_chose + "中标", r"第一中标候选人\1\2_fir"])
        self.config['replace_keyword_one'] = replace_word_ls

    def text_replace_word1(self):
        sql = 'select * from analyze_dispose where tag = 4'
        self.cursor.execute(sql)
        data = self.cursor.fetchall()
        replace_word_ls = []
        for i in data:
            replace_word_ls.append([i['NeedMatch'],i['UseKey'],i['NoMatch']])

        self.config['replace_keyword_two'] = replace_word_ls

    def pre_conf(self):
        need_keys_partone = {
            '^中标公司': self.config['company_chose'][0],
            '^负责人$': self.config['human_chose'][0],
            '^中标金额': '|',
            '^排名$': '^第\w名?$|^\d{1,20}$|^/$|(中标公司_)?第[一二三四五六七八九十]',
            '^标段$': '[ABCDEFGHIJKLMNOPQRSTUVEXYZ]|^[\d{1,3}一二三四五六七八九十]标?$|标[段包]|^/$|监理|施工|包|№|机$',
            '^价格类型$': '（?万元?）?',
            '^序号$': '^第\w名$',
            '^项目负责人资格': '|',
            '^项目负责人证书编号': '|',
            '^投标报价分': '|',
            '^总分': '|'
        }
        tag_word_partone = '^(中标候选情况（)?第?([一二三四五六七八九十\d]){1,3}(名|标?[段包]|合同段|中标)）?$|(包|标段|合同段)件([一二三四五六七八九十\d]){1,3}|中标公司_第[一二三四五六七八九十]'
        need_key_str_partone = '^中标公司(_第[一二三四五])?$|^(中标金额|original_)|^(负责人|项目负责人(资格|证书编号)|排名|投标报价分|总分|标段|价格类型|tag|title_tag)$|^中标公司-'
        need_keys_parttwo = {
            '^项目名称$': '|',
            '^评标成员': '|',
            '^标段$': '|',
            '^项目类型$': '|',
            '^项目地点$': '|',
            '^项目地点城市$': '|',
            '资[质格]要求$': '|',
            '投标要求$': '|',
            '^建设规模$': '|',
            '^工期$': '|',
            '^业主名称$': '|',
            '^业主地址$': '.{4,}',
            '联系人$': self.config['human_chose'][0],
            '联系电话$': '[\u4e00-\u9fa5]{0,}[\d-]+[\u4e00-\u9fa5]{0,}',
            '传真$': '[\u4e00-\u9fa5]{0,}[\d-]+[\u4e00-\u9fa5]{0,}',
            '^招标代理单位名称$': '|',
            '^招标代理单位地址$': '.{4,}',
            '^发布公告的媒介': '|',
            '^项目区域': '|',
            '^招标公告发布日期': '|',
            '^报名截止日期': '|',
            '资[质格]类别$': '|',
            '标的信息': '|',
            '^采购需求$':'|',
            '投资额':'|',
            '招标文件获取的时间': '|',
            '招标文件获取的地点': '|',
            '招标文件获取的方法': '|',
            '招标文件获取的售价': '|',
            '获取招标文件':'|',
            '资金来源': '|',
            '开标地点':'|',
            '标段划分':'|',
            '预算金额':'|',
            '核准单位':'|',
            '招标范围':'|',
            '是否接受联合体':'|',
            '核准文号':'|',
            '采购方式':'|',
            '^最高限价$':'|',
            '代理服务收费标准及金额':'|',
            '项目编号':'|',
            '开标时间':'|',
            '合同履行期限':'|'

        }

        province = ['河北', '山西', '辽宁', '吉林', '黑龙江', '江苏', '浙江', '安徽', '福建', '江西', '山东', '河南', '湖北', '湖南', '广东',
                    '海南', '四川', '贵州', '云南', '陕西', '甘肃', '青海', '台湾', '内蒙古', '广西', '西藏', '宁夏', '新疆', '北京', '天津',
                    '上海', '重庆', '香港', '澳门']

        self.config['need_keys_partone'] = need_keys_partone
        self.config['tag_word_partone'] = tag_word_partone
        self.config['need_key_str_partone'] = need_key_str_partone
        self.config['need_keys_parttwo'] = need_keys_parttwo
        self.config['province'] = province

    def text_pre_conf(self):
        replace_punctuation = [[r"\(", "（"], [r"\)", "）"], ["：", ":"], ["，", ","], ["；", ";"]]
        replace_label = [
            ["<(!doctype )?html>.*?(?=<body)>|</body>.*?</html>|<script.*?</script>|<style.*?</style>", ""],
            ["&nbsp;", " "],
            [r"</(t[dh]|p|div|h[23]|pre|table|li)>|<br.*?>|[ ]{2,}|\r?\n", "◄"],
            ['<!--\s{0,5}<.{0,100}?>\s{0,5}-->', ''],
            ["<.*?>", ""],
            [r" |\t|&[0-9a-z#]{2,};|\\|￥|¥", ""],
            ["◄{2,}", "◄"],
            ["/(span|strong|h2)|font-size|spanstyle=|font-family", ""],
        ]
        keyword = ["第一中标候选人", "中标金额", "项目负责人", "标段", "中标金额x"]
        move_not_key = [
            ["(?<=第一中标候选人).*?(?=第一中标候选人)"]
        ]
        find_key_replace_one = [
            ["直接发包", "(施工|监理)(企业|单位)[:◄]{0,6}(企业|单位)名称", "第一中标候选人"]
        ]

        find_tender = "([0-9一二三四五六七八九十ⅠⅡⅢⅣⅤⅥⅦⅧⅨⅩⅪⅫ]|施工|设计|勘察|监理){1,}标段?号?|标段号?[:◄]{0,}([0-9一二三四五六七八九十ⅠⅡⅢⅣⅤⅥⅦⅧⅨⅩⅪⅫ]|施工|设计|勘察|监理){1,}|(?<=◄)(施工|设计|勘察|监理)[:◄]|[0-9A-Z一二三四五六七八九十]+包|包[组号标][:◄]{1,5}[0-9A-Z一二三四五六七八九十]+|包\d+[:◄]{1,5}"
        find_tender_form_company = ":?标段:?([0-9一二三四五六七八九十ⅠⅡⅢⅣⅤⅥⅦⅧⅨⅩⅪⅫ]|施工|设计|勘察|监理){1,}|:?([0-9一二三四五六七八九十ⅠⅡⅢⅣⅤⅥⅦⅧⅨⅩⅪⅫ]|施工|设计|勘察|监理){1,}标段"

        self.config['replace_punctuation'] = replace_punctuation
        self.config['replace_label'] = replace_label
        self.config['keyword'] = keyword
        self.config['move_not_key'] = move_not_key
        self.config['find_key_replace_one'] = find_key_replace_one
        self.config['find_tender'] = find_tender
        self.config['find_tender_form_company'] = find_tender_form_company
    def text_choise(self,company_chose,human_chose):
        keyword_one = ["第一中标候选人", "中标金额", "项目负责人", "标段", "中标金额x"]
        find_winner = "(?<=第一中标候选人)(_(slow|fir))?[:◄]{0,6}([^►◄*]{3,25}" + company_chose + "){1,}"
        find_tender = "([0-9a-zA-Z一二三四五六七八九十ⅠⅡⅢⅣⅤⅥⅦⅧⅨⅩⅪⅫ]|施工|设计|勘察|监理){1,}标段?号?|标段号?[:◄]{0,}([0-9一二三四五六七八九十ⅠⅡⅢⅣⅤⅥⅦⅧⅨⅩⅪⅫ]|施工|设计|勘察|监理){1,}|(?<=◄)(施工|设计|勘察|监理)[:◄]|[0-9A-Z一二三四五六七八九十]+包|包[组号标][:◄]{1,5}[0-9A-Za-z一二三四五六七八九十]+|包\d+[:◄]{1,5}"
        find_winner_money = "(?<=中标金额)(（万?元）|为)?[:◄]{0,6}(（万?元）)?(\d+(\.\d+)(◄万元)?(（?万?元?）?)?|[^◄。;元%]+)"
        find_winner_money_ex = company_chose + "[:◄]{0,3}([零壹贰叁肆伍陆柒捌玖拾佰仟萬亿圆元万整]{3,})?（?\d+(\.\d+)?(%|万?元)?）?"
        find_winner_manage = r"(?<=项目负责人)[:◄]{0,6}([\u4e00-\u9fa5]◄[\u4e00-\u9fa5]◄|.*?(?=◄|,|。|\.|;|高级工程|工程师|一级建造师|二级建造师|获得的奖项|获得的业绩|拟投入本项目|工期))"

        replace_manage_name = [[
                                   "市政公用工程注册|国家注册造价工程师|注册建造师|公路工程|信息系统监理师|(机电|建筑)(工程|专业)|农技推广|专业|[一二三壹贰叁]级|[一二]级建造师|建[造][0-9A-Z]+|[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽黔贵粤青藏川宁琼]临?[0-9A-Z]+|(施工|安全|质量|材料员|机械|标准|劳务|资料)员|(证书|注册)编号|姓名|注册(证书|执业证)号|（[0-9a-z]+）|(建造?)[0-9A-Z]+|（?(证号|国家注册)）?|[0-9A-Z]+|、|级别及证书编号|,|，|：|；|;",
                                   ":"], ["项目负责人", ""]]
        find_winner_tender_type = ["第二中标候选人.+",
                                   "第?[0-9一二三四五六七八九十]{1,}|施工|设计|勘察|监理){1,}标段|(第?[0-9一二三四五六七八九十]{1,}(标段)|施工|设计|勘察|监理|[0-9A-Z一二三四五六七八九十]+包):?◄?\s{0,5}第一中标候选人"]
        find_tender_form_company = ":?标段:?([0-9一二三四五六七八九十ⅠⅡⅢⅣⅤⅥⅦⅧⅨⅩⅪⅫ]|施工|设计|勘察|监理){1,}|:?([0-9一二三四五六七八九十ⅠⅡⅢⅣⅤⅥⅦⅧⅨⅩⅪⅫ]|施工|设计|勘察|监理){1,}标段"
        find_key_one = [{"key": "标段", "value": find_tender}, {"key": "第一中标候选人", "value": find_winner},
                        {"key": "中标金额", "value": find_winner_money}, {"key": "中标金额x", "value": find_winner_money_ex},
                        {"key": "项目负责人", "value": find_winner_manage}]
        self.config['keyword_one'] = keyword_one
        self.config['find_winner_manage_name'] = human_chose
        self.config['replace_manage_name'] = replace_manage_name
        self.config['find_winner_tender_type'] = find_winner_tender_type
        self.config['find_tender_form_company'] = find_tender_form_company
        self.config['find_key_one'] = find_key_one
        find_key_two = {
            '项目名称': ['|', '-10000000'],
            '评标成员': ['|', '-10000000'],
            '标段': ['|', '-10000000'],
            '项目类型': ['|', '-10000000'],
            '项目地点': ['|', '-10000000'],
            '项目地点城市': ['|', '-10000000'],
            '投标要求': ['|', '-10000000'],
            '建设规模': ['|', '-10000000'],
            '建设规模_fir': ['|', '-10000000'],
            '工期': ['[\d一二三四五六七八九十年月日]|招标|要求|阶段', '-10000000'],
            '业主名称': ['.{4,}', '资格要求|名称|盖章|签名'],
            '招标代理单位名称': [company_chose, '-10000000'],
            '发布公告的媒介': ['|', '-10000000'],
            '发布公告的媒介-especial': ['|', '-10000000'],
            '项目区域': ['|', '-10000000'],
            '招标公告发布日期': ['|', '-10000000'],
            '报名截止日期': ['[\d年月日]', '-10000000'],
            '企业资质类别': ['|', '-10000000'],
            '人员资格类别': ['|', '-10000000'],
            '联系人': [
                human_chose,
                '^\d.*?日$'],
            '联系电话': ['\w+\d{3,4}-\d{7,8}|\w+[\d-]{6,12}|^/$', '-10000000'],
            '地址': ['.{4,}', '-10000000'],
            '传真': ['|', '-10000000'],
            '业主联系人': [
                human_chose,
                '-10000000'],
            '业主联系电话': ['\w+\d{3,4}-\d{7,8}|\w+[\d-]{6,12}|^/$', '-10000000'],
            '业主地址': ['.{4,}', '-10000000'],
            '业主传真': ['|', '-10000000'],
            '招标代理单位联系人': [
                human_chose,
                '-10000000'],
            '招标代理单位联系电话': ['\w+\d{3,4}-\d{7,8}|\w+[\d-]{6,12}|^/$', '-10000000'],
            '招标代理单位地址': ['.{4,}', '-10000000'],
            '招标代理单位传真': ['|', '-10000000'],
            '项目资质要求': ['|', '-10000000'],
            '名称': ['.{4,}', '盖章|签名'],
            '电子邮件': ['-1000000', '-100000'],
            '标的信息': ['|', "-100000"],
            '采购需求': ['|',"^序号$"],
            '开标地点': ['|', "-100000"],
            '招标文件获取的时间':['|',"-100000"],
            '招标文件获取的地点':['|',"-100000"],
            '招标文件获取的方法': ['|', "-100000"],
            '招标文件获取的售价': ['|', "-100000"],
            '获取招标文件':['|','-100000'],
            '资金来源':['|','-100000'],
            '开标地点':['|','-100000'],
            '标段划分':['|','-100000'],
            '开标数据':['|','-100000'],
            '核准单位':['|','-100000'],
            '招标范围':['|','-100000'],
            '投资额':['|','-100000'],
            '核准文号':['|','-100000'],
            '采购方式':['|','-100000'],
            '最高限价':['|','-1000000'],
            '预算金额':['|','-100000'],
            '代理服务收费标准及金额':['|','-1000000'],
            '项目编号':['|','-1000000'],
            '开标时间':['|','-1000000'],
            '合同履行期限':['|','-1000000'],
            '是否接受联合体': ['|','-1000000']
        }
        self.config['find_key_two'] = find_key_two
    def re_ls(self):
        sql = 'select * from analyze_dispose where tag = 5'
        self.cursor.execute(sql)
        data = self.cursor.fetchall()
        replace_word_ls = []
        for i in data:
            replace_word_ls.append([i['NeedMatch'], i['UseKey']])
        self.config['re_ls'] = replace_word_ls
        sql = 'select * from analyze_dispose where tag = 6'
        self.cursor.execute(sql)
        data = self.cursor.fetchall()
        replace_word_ls = []
        for i in data:
            replace_word_ls.append([i['NeedMatch'], i['UseKey']])
        self.config['re_ls_before'] = replace_word_ls
    def dispose_solo_text(self):
        sql = 'select * from analyze_dispose_solo where tag = 1'
        self.cursor.execute(sql)
        data = self.cursor.fetchall()
        dispose_solo_text_dict = defaultdict(list)
        for i in data:
            dispose_solo_text_dict[i['data_source_id']].append([i['NeedMatch'],i['UseKey']])
        self.config['dispose_solo_text_dict'] = dispose_solo_text_dict
        sql = 'select * from analyze_dispose_solo where tag = 2'
        self.cursor.execute(sql)
        data = self.cursor.fetchall()
        dispose_solo_text_dict_before = defaultdict(list)
        for i in data:
            dispose_solo_text_dict_before[i['data_source_id']].append([i['NeedMatch'], i['UseKey']])
        self.config['dispose_solo_text_dict_before'] = dispose_solo_text_dict_before



    def main(self):
        self.tag()
        self.table_clear_word()
        self.table_replace_word()
        self.public_word()
        self.pre_conf()
        self.text_pre_conf()
        self.text_replace_word(self.config['company_chose'][0])
        self.text_replace_word1()
        self.text_choise(self.config['company_chose'][0],self.config['human_chose'][0])
        self.re_ls()
        self.dispose_solo_text()
        return self.config

if __name__ == '__main__':
    conn = pymysql.connect(
        host='122.112.153.139',
        port=3306,
        user='root',
        passwd='Lubanjianye999!@',
        charset='utf8',
        database='data_collection_server',
        cursorclass=pymysql.cursors.DictCursor)
    cursor = conn.cursor()
    args = {'conn':conn,
            'cursor':cursor}
    conf = Conf(**args)
    config = conf.main()
    confunc = ConFunc(config)

